//
//  MenuWindowView.m
//  LightControl
//
//  Created by CKF on 2025/8/19.
//

#import "MenuWindowView.h"
#import "MenuView.h"
@interface MenuWindowView()<AddMenuOperation>

@property (nonatomic, strong) MenuView *menu;
@end
@implementation MenuWindowView

- (instancetype)initWithFrame:(CGRect)frame {
    self = [super initWithFrame:frame];
    if (self) {
        self.backgroundColor = [UIColor clearColor];
        _menu = [[MenuView alloc] initWithSetCellLabelTextWithArray:@[LocalString(@"详情"),LocalString(@"日志"),LocalString(@"删除")] menuPoint:CGPointMake(KScreenWidth-100, 0) withMenuStyle:MenuDefaultStyle];
        _menu.delegate = self;
        [self addSubview:_menu];
        
        // 假设你的子视图是 childView，父视图是 parentView
        UITapGestureRecognizer *tapGesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleTap:)];
        [self addGestureRecognizer:tapGesture];
    }
    return self;
}

-(void)display{
    [_menu display];
}
-(void)hide{
    [_menu disappear];
}

- (void)handleTap:(UITapGestureRecognizer *)gesture {
    CGPoint tapPoint = [gesture locationInView:self];
        
    // 判断点击位置是否在子视图外
    if (!CGRectContainsPoint(_menu.frame, tapPoint)) {
        [_menu disappear];
    }
}
@end
